package com.web.web;


import com.web.entity.NoteType;
import com.web.param.DelNoteTypeDto;
import com.web.param.InsertNoteTypeDto;
import com.web.param.InsertUserDto;
import com.web.param.UpdateNoteType;
import com.web.service.INoteTypeService;
import com.web.util.BaseController;
import com.web.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 笔记类型表 前端控制器
 * </p>
 *
 * @author hgjxyz
 * @since 2020-11-18
 */
@Api(tags = "笔记类型表")
@RestController
@RequestMapping("/web/noteType")
public class NoteTypeController extends BaseController {

    @Autowired private INoteTypeService noteTypeService;

    @ApiOperation("添加分类")
    @PostMapping("add")
    public JsonResult<NoteType> add(@RequestBody InsertNoteTypeDto dto) {
        return new JsonResult<>(this.noteTypeService.add(dto.getName(), dto.getToken()));
    }

    @ApiOperation("删除分类")
    @PostMapping("delete")
    public JsonResult<Void> delete(@RequestBody DelNoteTypeDto dto) {
        this.noteTypeService.delete(dto.getId(), dto.getToken());
        return new JsonResult<>(null);
    }

    @ApiOperation("修改分类")
    @PostMapping("update")
    public JsonResult<Void> update(@RequestBody UpdateNoteType dto) {
        this.noteTypeService.update(dto.getId(), dto.getName(), dto.getToken());
        return new JsonResult<>(null);
    }

    @ApiOperation("查询自己的所有分类")
    @GetMapping(value = "get/{token}")
    public JsonResult<List<NoteType>> getList(
            @ApiParam(name = "token", value = "token", required = true)@PathVariable("token") String token) {
        return new JsonResult<>(this.noteTypeService.getList(token));
    }

}

